<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0031)http://b2core.b24.cn/page/code/ -->
<html xmlns="http://www.w3.org/1999/xhtml" class="hb-loaded"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

  <title>代码及注释</title>
  <meta name="keywords" content="代码及注释">
  <meta name="description" content="代码及注释">
  <link href="./代码及注释_files/default.css" rel="stylesheet" type="text/css" media="screen">
  <!--<base href="http://b2core.b24.cn/">--><base href=".">
<style id="style-1-cropbar-clipper">/* Copyright 2014 Evernote Corporation. All rights reserved. */
.en-markup-crop-options {
    top: 18px !important;
    left: 50% !important;
    margin-left: -100px !important;
    width: 200px !important;
    border: 2px rgba(255,255,255,.38) solid !important;
    border-radius: 4px !important;
}

.en-markup-crop-options div div:first-of-type {
    margin-left: 0px !important;
}
</style></head>
<body huaban_collector_injected="true">
<div id="wrapper">
  <div id="page-content">
    <div id="header-wrapper">
      <div id="header">
        <div id="logo">
          <h1><a href="http://b2core.b24.cn/"><img src="./代码及注释_files/20120501081847_44850.png" alt="b2Core"></a></h1>
          <p>轻量 php MVC 架构</p>
        </div>
      </div>
    </div>
    <!-- end #header -->
    <div id="menu-wrapper">
      <div id="menu">
        <ul>
              <li class="first"><a href=""><span>首页</span></a></li><li><a href="http://b2core.b24.cn/page/help/"><span>使用入门</span></a></li><li><a href="http://b2core.b24.cn/page/code/"><span>代码及注释</span></a></li><li><a href="http://b2core.b24.cn/page/lib/"><span>类库</span></a></li><li><a href="http://alpaca.b24.cn/bbs/forum/13/" target="_blank"><span>讨论</span></a></li>	
        </ul>
      </div>
    </div>
    <!-- end #menu -->
    <div id="banner"></div>
    <div class="padding">
      <div id="breadcrumb" class="post">
         <a href="http://b2core.b24.cn/">首页</a> »       </div>
      <div class="post">
      <style>
.code{
font-family: monospace;
}
.code td,.code th{padding:0;}
.code th{padding-right:20px;text-align:right;color:#aaa;}
</style>


代码以及注释 <h4>app/b2core.php</h4>
<div class="notice">
<table class="code">
<tbody><tr>
<th>1</th>
<td width="100%" nowrap="" style="color: green;"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php</span></span></code></td>
</tr>
<tr>
<th>2</th>
<td width="100%" nowrap="" style="color: orange;"><span style="color: #FF8000">/**</span></td>
</tr>
<tr>
<th>3</th>
<td width="100%" nowrap="" style="color: orange;">&nbsp;*&nbsp;B2Core&nbsp;是由&nbsp;Brant&nbsp;(brantx@gmail.com)发起的基于PHP的MVC架构</td>
</tr>
<tr>
<th>4</th>
<td width="100%" nowrap="" style="color: orange;">&nbsp;*&nbsp;核心思想是在采用MVC框架的基础上最大限度的保留php的灵活性</td>
</tr>
<tr>
<th>5</th>
<td width="100%" nowrap="" style="color: orange;">&nbsp;*&nbsp;*/</td>
</tr>
<tr>
<th>6</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>7</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">define</span><span style="color: #007700">(</span><span style="color: #DD0000">'B2CORE_VERSION'</span><span style="color: #007700">,</span><span style="color: #DD0000">'2.0'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>8</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>9</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;载入配置文件：数据库、url路由等等&nbsp;</span></td>
</tr>
<tr>
<th>10</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">require(</span><span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #DD0000">'config.php'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>11</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>12</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;如果配置了数据库则载入</span></td>
</tr>
<tr>
<th>13</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">if(isset(</span><span style="color: #0000BB">$db_config</span><span style="color: #007700">)){</span></td>
</tr>
<tr>
<th>14</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$db&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">db</span><span style="color: #007700">(</span><span style="color: #0000BB">$db_config</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>15</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>16</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>17</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;获取请求的地址兼容&nbsp;SAE</span></td>
</tr>
<tr>
<th>18</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>19</th>
<td width="100%" nowrap="" style="color: green;">if(isset(<span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'PATH_INFO'</span><span style="color: #007700">]))&nbsp;</span><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'PATH_INFO'</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>20</th>
<td width="100%" nowrap="" style="color: green;">if(isset(<span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'ORIG_PATH_INFO'</span><span style="color: #007700">]))&nbsp;</span><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'ORIG_PATH_INFO'</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>21</th>
<td width="100%" nowrap="" style="color: green;">if(isset(<span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'SCRIPT_URL'</span><span style="color: #007700">]))&nbsp;</span><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'SCRIPT_URL'</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>22</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">render_url</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>23</th>
<td width="100%" nowrap="" style="color: green;">function&nbsp;<span style="color: #0000BB">render_url</span><span style="color: #007700">()</span></td>
</tr>
<tr>
<th>24</th>
<td width="100%" nowrap="" style="color: green;">{&nbsp;</td>
</tr>
<tr>
<th>25</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;redirect&nbsp;abc/def&nbsp;to&nbsp;abc/def/&nbsp;to&nbsp;make&nbsp;SEO&nbsp;url&nbsp;</span></td>
</tr>
<tr>
<th>26</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">global&nbsp;</span><span style="color: #0000BB">$uri</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>27</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">strpos</span><span style="color: #007700">(</span><span style="color: #0000BB">$uri</span><span style="color: #007700">,</span><span style="color: #DD0000">'.'</span><span style="color: #007700">))return;</span></td>
</tr>
<tr>
<th>28</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'QUERY_STRING'</span><span style="color: #007700">])return;</span></td>
</tr>
<tr>
<th>29</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">substr</span><span style="color: #007700">(</span><span style="color: #0000BB">$uri</span><span style="color: #007700">,-</span><span style="color: #0000BB">1</span><span style="color: #007700">)==</span><span style="color: #DD0000">'/'</span><span style="color: #007700">)return;</span></td>
</tr>
<tr>
<th>30</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">==</span><span style="color: #DD0000">''</span><span style="color: #007700">)return;</span></td>
</tr>
<tr>
<th>31</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"HTTP/1.1&nbsp;301&nbsp;Moved&nbsp;Permanently"</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>32</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">header&nbsp;</span><span style="color: #007700">(</span><span style="color: #DD0000">'Location:'</span><span style="color: #007700">.</span><span style="color: #0000BB">$_SERVER</span><span style="color: #007700">[</span><span style="color: #DD0000">'REQUEST_URI'</span><span style="color: #007700">].</span><span style="color: #DD0000">'/'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>33</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;exit(<span style="color: #0000BB">0</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>34</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>35</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>36</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//echo&nbsp;'&nbsp;去除Magic_Quotes';</span></td>
</tr>
<tr>
<th>37</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">if(</span><span style="color: #0000BB">get_magic_quotes_gpc</span><span style="color: #007700">())&nbsp;</span><span style="color: #FF8000">//&nbsp;Maybe&nbsp;would&nbsp;be&nbsp;removed&nbsp;in&nbsp;php6</span></td>
</tr>
<tr>
<th>38</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">{</span></td>
</tr>
<tr>
<th>39</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">stripslashes_deep</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>40</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>41</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$value&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #0000BB">array_map</span><span style="color: #007700">(</span><span style="color: #DD0000">'stripslashes_deep'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;:&nbsp;(isset(</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #0000BB">stripslashes</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;:&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>42</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$value</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>43</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>44</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$_POST&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stripslashes_deep</span><span style="color: #007700">(</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>45</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$_GET&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stripslashes_deep</span><span style="color: #007700">(</span><span style="color: #0000BB">$_GET</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>46</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$_COOKIE&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stripslashes_deep</span><span style="color: #007700">(</span><span style="color: #0000BB">$_COOKIE</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>47</th>
<td width="100%" nowrap="" style="color: green;">}&nbsp;</td>
</tr>
<tr>
<th>48</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>49</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;执行&nbsp;config.php&nbsp;中配置的url路由</span></td>
</tr>
<tr>
<th>50</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">foreach&nbsp;(</span><span style="color: #0000BB">$route_config&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>51</th>
<td width="100%" nowrap="" style="color: green;">{&nbsp;</td>
</tr>
<tr>
<th>52</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">':any'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'([^\/.]+)'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">str_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">':num'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'([0-9]+)'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">));</span></td>
</tr>
<tr>
<th>53</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if&nbsp;(<span style="color: #0000BB">preg_match</span><span style="color: #007700">(</span><span style="color: #DD0000">'#^'</span><span style="color: #007700">.</span><span style="color: #0000BB">$key</span><span style="color: #007700">.</span><span style="color: #DD0000">'#'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$uri</span><span style="color: #007700">))</span><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">preg_replace</span><span style="color: #007700">(</span><span style="color: #DD0000">'#^'</span><span style="color: #007700">.</span><span style="color: #0000BB">$key</span><span style="color: #007700">.</span><span style="color: #DD0000">'#'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$uri</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>54</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>55</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>56</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//echo&nbsp;'&nbsp;获取URL中每一段的参数';</span></td>
</tr>
<tr>
<th>57</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$uri&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">rtrim</span><span style="color: #007700">(</span><span style="color: #0000BB">$uri</span><span style="color: #007700">,</span><span style="color: #DD0000">'/'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>58</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$seg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'/'</span><span style="color: #007700">,</span><span style="color: #0000BB">$uri</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>59</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$des_dir&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dir&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>60</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>61</th>
<td width="100%" nowrap="" style="color: orange;"><span style="color: #FF8000">/*&nbsp;依次载入控制器上级所有目录的架构文件&nbsp;__construct.php</span></td>
</tr>
<tr>
<th>62</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;架构文件可以包含当前目录下的所有控制器的父类，和需要调用的函数&nbsp;</td>
</tr>
<tr>
<th>63</th>
<td width="100%" nowrap="" style="color: orange;">*/</td>
</tr>
<tr>
<th>64</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>65</th>
<td width="100%" nowrap="" style="color: green;">//echo&nbsp;'look';</td>
</tr>
<tr>
<th>66</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">foreach(</span><span style="color: #0000BB">$seg&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$cur_dir</span><span style="color: #007700">)&nbsp;</span></td>
</tr>
<tr>
<th>67</th>
<td width="100%" nowrap="" style="color: green;">{</td>
</tr>
<tr>
<th>68</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$des_dir</span><span style="color: #007700">.=</span><span style="color: #0000BB">$cur_dir</span><span style="color: #007700">.</span><span style="color: #DD0000">"/"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>69</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">is_file</span><span style="color: #007700">(</span><span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #DD0000">'c'</span><span style="color: #007700">.</span><span style="color: #0000BB">$des_dir</span><span style="color: #007700">.</span><span style="color: #DD0000">'__construct.php'</span><span style="color: #007700">))&nbsp;{</span></td>
</tr>
<tr>
<th>70</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;require(<span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #DD0000">'c'</span><span style="color: #007700">.</span><span style="color: #0000BB">$des_dir</span><span style="color: #007700">.</span><span style="color: #DD0000">'__construct.php'</span><span style="color: #007700">);&nbsp;</span></td>
</tr>
<tr>
<th>71</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$dir&nbsp;</span><span style="color: #007700">.=</span><span style="color: #0000BB">array_shift</span><span style="color: #007700">(</span><span style="color: #0000BB">$seg</span><span style="color: #007700">).</span><span style="color: #DD0000">'/'</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>72</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>73</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;else&nbsp;{</td>
</tr>
<tr>
<th>74</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;break;</td>
</tr>
<tr>
<th>75</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>76</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>77</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>78</th>
<td width="100%" nowrap="" style="color: orange;"><span style="color: #FF8000">/*&nbsp;根据&nbsp;url&nbsp;调用控制器中的方法，如果不存在返回&nbsp;404&nbsp;错误</span></td>
</tr>
<tr>
<th>79</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;默认请求&nbsp;class&nbsp;home-&gt;index()</td>
</tr>
<tr>
<th>80</th>
<td width="100%" nowrap="" style="color: orange;">*/</td>
</tr>
<tr>
<th>81</th>
<td width="100%" nowrap="" style="color: green;">//echo&nbsp;&nbsp;'默认请求&nbsp;class&nbsp;home-&gt;index()';</td>
</tr>
<tr>
<th>82</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$dir&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dir&nbsp;</span><span style="color: #007700">?&nbsp;</span><span style="color: #0000BB">$dir</span><span style="color: #007700">:</span><span style="color: #DD0000">'/'</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>83</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">array_unshift</span><span style="color: #007700">(</span><span style="color: #0000BB">$seg</span><span style="color: #007700">,</span><span style="color: #0000BB">NULL</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>84</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$class&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;isset(</span><span style="color: #0000BB">$seg</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">])?</span><span style="color: #0000BB">$seg</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]:</span><span style="color: #DD0000">'home'</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>85</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$method&nbsp;</span><span style="color: #007700">=&nbsp;isset(</span><span style="color: #0000BB">$seg</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">])?</span><span style="color: #0000BB">$seg</span><span style="color: #007700">[</span><span style="color: #0000BB">2</span><span style="color: #007700">]:</span><span style="color: #DD0000">'index'</span><span style="color: #007700">;&nbsp;</span></td>
</tr>
<tr>
<th>86</th>
<td width="100%" nowrap="" style="color: green;">if(!<span style="color: #0000BB">is_file</span><span style="color: #007700">(</span><span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #DD0000">'c'</span><span style="color: #007700">.</span><span style="color: #0000BB">$dir</span><span style="color: #007700">.</span><span style="color: #0000BB">$class</span><span style="color: #007700">.</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">))</span><span style="color: #0000BB">show_404</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>87</th>
<td width="100%" nowrap="" style="color: green;">require(<span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #DD0000">'c'</span><span style="color: #007700">.</span><span style="color: #0000BB">$dir</span><span style="color: #007700">.</span><span style="color: #0000BB">$class</span><span style="color: #007700">.</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>88</th>
<td width="100%" nowrap="" style="color: green;">if(!<span style="color: #0000BB">class_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$class</span><span style="color: #007700">))</span><span style="color: #0000BB">show_404</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>89</th>
<td width="100%" nowrap="" style="color: green;">if(!<span style="color: #0000BB">method_exists</span><span style="color: #007700">(</span><span style="color: #0000BB">$class</span><span style="color: #007700">,</span><span style="color: #0000BB">$method</span><span style="color: #007700">))</span><span style="color: #0000BB">show_404</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>90</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">$B2&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">$class</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>91</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(array(&amp;</span><span style="color: #0000BB">$B2</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$method</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">array_slice</span><span style="color: #007700">(</span><span style="color: #0000BB">$seg</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">));</span></td>
</tr>
<tr>
<th>92</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>93</th>
<td width="100%" nowrap="" style="color: orange;"><span style="color: #FF8000">/*&nbsp;B2&nbsp;系统函数&nbsp;</span></td>
</tr>
<tr>
<th>94</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;load($path,$instantiate)&nbsp;可以动态载入对象，如：控制器、Model、库类等</td>
</tr>
<tr>
<th>95</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;$path&nbsp;是类文件相对&nbsp;app&nbsp;的地址</td>
</tr>
<tr>
<th>96</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;$instantiate&nbsp;为&nbsp;False&nbsp;时，仅引用文件，不实例化对象</td>
</tr>
<tr>
<th>97</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;$instantiate&nbsp;为数组时，数组内容会作为参数传递给对象&nbsp;</td>
</tr>
<tr>
<th>98</th>
<td width="100%" nowrap="" style="color: orange;">*/</td>
</tr>
<tr>
<th>99</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;</td>
</tr>
<tr>
<th>100</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">function&nbsp;&amp;</span><span style="color: #0000BB">load</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$instantiate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TRUE&nbsp;</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>101</th>
<td width="100%" nowrap="" style="color: green;">{</td>
</tr>
<tr>
<th>102</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$param&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>103</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">is_array</span><span style="color: #007700">(</span><span style="color: #0000BB">$instantiate</span><span style="color: #007700">))&nbsp;{</span></td>
</tr>
<tr>
<th>104</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$param&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$instantiate</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>105</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$instantiate&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>106</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>107</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">'/'</span><span style="color: #007700">,</span><span style="color: #0000BB">$path</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>108</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$class_name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_pop</span><span style="color: #007700">(</span><span style="color: #0000BB">$file</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>109</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">$object_name&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">md5</span><span style="color: #007700">(</span><span style="color: #0000BB">$path</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>110</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;</td>
</tr>
<tr>
<th>111</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;static&nbsp;<span style="color: #0000BB">$objects&nbsp;</span><span style="color: #007700">=&nbsp;array();</span></td>
</tr>
<tr>
<th>112</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if&nbsp;(isset(<span style="color: #0000BB">$objects</span><span style="color: #007700">[</span><span style="color: #0000BB">$object_name</span><span style="color: #007700">]))&nbsp;return&nbsp;</span><span style="color: #0000BB">$objects</span><span style="color: #007700">[</span><span style="color: #0000BB">$object_name</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>113</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;require(<span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #0000BB">$path</span><span style="color: #007700">.</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>114</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if&nbsp;(<span style="color: #0000BB">$instantiate&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">$objects</span><span style="color: #007700">[</span><span style="color: #0000BB">$object_name</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>115</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;elseif&nbsp;(<span style="color: #0000BB">$param</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">$objects</span><span style="color: #007700">[</span><span style="color: #0000BB">$object_name</span><span style="color: #007700">]&nbsp;=&nbsp;new&nbsp;</span><span style="color: #0000BB">$class_name</span><span style="color: #007700">(</span><span style="color: #0000BB">$param</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>116</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;else&nbsp;&nbsp;<span style="color: #0000BB">$objects</span><span style="color: #007700">[</span><span style="color: #0000BB">$object_name</span><span style="color: #007700">]&nbsp;=&nbsp;new&nbsp;</span><span style="color: #0000BB">$class_name</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>117</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$objects</span><span style="color: #007700">[</span><span style="color: #0000BB">$object_name</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>118</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>119</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>120</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;取得&nbsp;url&nbsp;的片段，如&nbsp;url&nbsp;是&nbsp;/abc/def/g/&nbsp;&nbsp;seg(1)&nbsp;=&nbsp;abc</span></td>
</tr>
<tr>
<th>121</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">seg</span><span style="color: #007700">(</span><span style="color: #0000BB">$i</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>122</th>
<td width="100%" nowrap="" style="color: green;">{</td>
</tr>
<tr>
<th>123</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;global&nbsp;<span style="color: #0000BB">$seg</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>124</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;return&nbsp;isset(<span style="color: #0000BB">$seg</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">])?</span><span style="color: #0000BB">$seg</span><span style="color: #007700">[</span><span style="color: #0000BB">$i</span><span style="color: #007700">]:</span><span style="color: #0000BB">false</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>125</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>126</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>127</th>
<td width="100%" nowrap="" style="color: orange;"><span style="color: #FF8000">/*&nbsp;调用&nbsp;view&nbsp;文件</span></td>
</tr>
<tr>
<th>128</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;function&nbsp;view($view,$param&nbsp;=&nbsp;array(),$cache&nbsp;=&nbsp;FALSE)</td>
</tr>
<tr>
<th>129</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;$view&nbsp;是模板文件相对&nbsp;app/v/&nbsp;目录的地址，地址应去除&nbsp;.php&nbsp;文件后缀</td>
</tr>
<tr>
<th>130</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;$param&nbsp;数组中的变量会传递给模板文件</td>
</tr>
<tr>
<th>131</th>
<td width="100%" nowrap="" style="color: orange;">*&nbsp;$cache&nbsp;=&nbsp;TRUE&nbsp;时，不像浏览器输出结果，而是以&nbsp;string&nbsp;的形式&nbsp;return</td>
</tr>
<tr>
<th>132</th>
<td width="100%" nowrap="" style="color: orange;">*/</td>
</tr>
<tr>
<th>133</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">view</span><span style="color: #007700">(</span><span style="color: #0000BB">$view</span><span style="color: #007700">,</span><span style="color: #0000BB">$param&nbsp;</span><span style="color: #007700">=&nbsp;array(),</span><span style="color: #0000BB">$cache&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>134</th>
<td width="100%" nowrap="" style="color: green;">{</td>
</tr>
<tr>
<th>135</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(!empty(<span style="color: #0000BB">$param</span><span style="color: #007700">))</span><span style="color: #0000BB">extract</span><span style="color: #007700">(</span><span style="color: #0000BB">$param</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>136</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">ob_start</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>137</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;if(<span style="color: #0000BB">is_file</span><span style="color: #007700">(</span><span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #0000BB">$view</span><span style="color: #007700">.</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">))&nbsp;{</span></td>
</tr>
<tr>
<th>138</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;require&nbsp;<span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #0000BB">$view</span><span style="color: #007700">.</span><span style="color: #DD0000">'.php'</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>139</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>140</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;else&nbsp;{</td>
</tr>
<tr>
<th>141</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span style="color: #DD0000">'view&nbsp;'</span><span style="color: #007700">.</span><span style="color: #0000BB">$view</span><span style="color: #007700">.</span><span style="color: #DD0000">'&nbsp;desn\'t&nbsp;exsit'</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>142</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">false</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>143</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>144</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;Return&nbsp;the&nbsp;file&nbsp;data&nbsp;if&nbsp;requested</span></td>
</tr>
<tr>
<th>145</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$cache&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>146</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>147</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$buffer&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">ob_get_contents</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>148</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;@<span style="color: #0000BB">ob_end_clean</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>149</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$buffer</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>150</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>151</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>152</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>153</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;写入日志</span></td>
</tr>
<tr>
<th>154</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">write_log</span><span style="color: #007700">(</span><span style="color: #0000BB">$level&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">,</span><span style="color: #0000BB">$content&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'none'</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>155</th>
<td width="100%" nowrap="" style="color: green;">{</td>
</tr>
<tr>
<th>156</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">file_put_contents</span><span style="color: #007700">(</span><span style="color: #0000BB">APP</span><span style="color: #007700">.</span><span style="color: #DD0000">'log/'</span><span style="color: #007700">.</span><span style="color: #0000BB">$level</span><span style="color: #007700">.</span><span style="color: #DD0000">'-'</span><span style="color: #007700">.</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">).</span><span style="color: #DD0000">'.log'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$content&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">FILE_APPEND&nbsp;</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>157</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>158</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>159</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//echo&nbsp;'&nbsp;显示404错误';</span></td>
</tr>
<tr>
<th>160</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">show_404</span><span style="color: #007700">()&nbsp;</span><span style="color: #FF8000">//显示&nbsp;404&nbsp;错误</span></td>
</tr>
<tr>
<th>161</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">{</span></td>
</tr>
<tr>
<th>162</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"HTTP/1.1&nbsp;404&nbsp;Not&nbsp;Found"</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>163</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;调用&nbsp;模板&nbsp;v/404.php&nbsp;</span></td>
</tr>
<tr>
<th>164</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #0000BB">view</span><span style="color: #007700">(</span><span style="color: #DD0000">'v/404'</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>165</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;exit(<span style="color: #0000BB">1</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>166</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>167</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>168</th>
<td width="100%" nowrap="" style="color: orange;"><span style="color: #FF8000">/*&nbsp;&nbsp;B2Core&nbsp;系统类&nbsp;*/</span></td>
</tr>
<tr>
<th>169</th>
<td width="100%" nowrap="" style="color: green;">//&nbsp;抽象的控制器类，建议所有的控制器均基层此类或者此类的子类&nbsp;</td>
</tr>
<tr>
<th>170</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">c&nbsp;</span><span style="color: #007700">{&nbsp;</span></td>
</tr>
<tr>
<th>171</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">index</span><span style="color: #007700">()</span></td>
</tr>
<tr>
<th>172</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>173</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span style="color: #DD0000">"基于&nbsp;B2&nbsp;v"</span><span style="color: #007700">.</span><span style="color: #0000BB">VERSION</span><span style="color: #007700">.</span><span style="color: #DD0000">"&nbsp;创建"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>174</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>175</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>176</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>177</th>
<td width="100%" nowrap="" style="color: green;">class&nbsp;<span style="color: #0000BB">db&nbsp;</span><span style="color: #007700">{&nbsp;</span></td>
</tr>
<tr>
<th>178</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;var&nbsp;<span style="color: #0000BB">$link</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>179</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;var&nbsp;<span style="color: #0000BB">$last_query</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>180</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">__construct</span><span style="color: #007700">(</span><span style="color: #0000BB">$conf</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>181</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>182</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">link&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$conf</span><span style="color: #007700">[</span><span style="color: #DD0000">'host'</span><span style="color: #007700">],</span><span style="color: #0000BB">$conf</span><span style="color: #007700">[</span><span style="color: #DD0000">'user'</span><span style="color: #007700">],&nbsp;</span><span style="color: #0000BB">$conf</span><span style="color: #007700">[</span><span style="color: #DD0000">'password'</span><span style="color: #007700">]);</span></td>
</tr>
<tr>
<th>183</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">link</span><span style="color: #007700">)&nbsp;{</span></td>
</tr>
<tr>
<th>184</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(<span style="color: #DD0000">'无法连接:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</span></td>
</tr>
<tr>
<th>185</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">FALSE</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>186</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>187</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>188</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$db_selected&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_select_db</span><span style="color: #007700">(</span><span style="color: #0000BB">$conf</span><span style="color: #007700">[</span><span style="color: #DD0000">'default_db'</span><span style="color: #007700">]);</span></td>
</tr>
<tr>
<th>189</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!<span style="color: #0000BB">$db_selected</span><span style="color: #007700">)&nbsp;{</span></td>
</tr>
<tr>
<th>190</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die(<span style="color: #DD0000">'无法使用&nbsp;:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());</span></td>
</tr>
<tr>
<th>191</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>192</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">'set&nbsp;names&nbsp;utf8'</span><span style="color: #007700">,</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">link</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>193</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>194</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>195</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//执行&nbsp;query&nbsp;查询，如果结果为数组，则返回数组数据</span></td>
</tr>
<tr>
<th>196</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>197</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>198</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;array();</span></td>
</tr>
<tr>
<th>199</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">last_query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>200</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">,</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">link</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>201</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!<span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{</span></td>
</tr>
<tr>
<th>202</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span style="color: #DD0000">"DB&nbsp;Error,&nbsp;could&nbsp;not&nbsp;query&nbsp;the&nbsp;database\n"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>203</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span style="color: #DD0000">'MySQL&nbsp;Error:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>204</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;<span style="color: #DD0000">'Error&nbsp;Query:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>205</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit;</td>
</tr>
<tr>
<th>206</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>207</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if(<span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #0000BB">1&nbsp;</span><span style="color: #007700">)return&nbsp;</span><span style="color: #0000BB">TRUE</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>208</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;while(<span style="color: #0000BB">$record&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_fetch_assoc</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))</span></td>
</tr>
<tr>
<th>209</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>210</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$ret</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$record</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>211</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>212</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$ret</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>213</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>214</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>215</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">insert_id</span><span style="color: #007700">()&nbsp;{return&nbsp;</span><span style="color: #0000BB">mysql_insert_id</span><span style="color: #007700">();}</span></td>
</tr>
<tr>
<th>216</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;</td>
</tr>
<tr>
<th>217</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;执行多条&nbsp;SQL&nbsp;语句</span></td>
</tr>
<tr>
<th>218</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">muti_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>219</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>220</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$sq&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">explode</span><span style="color: #007700">(</span><span style="color: #DD0000">";\n"</span><span style="color: #007700">,</span><span style="color: #0000BB">$query</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>221</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;foreach(<span style="color: #0000BB">$sq&nbsp;&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$s</span><span style="color: #007700">){</span></td>
</tr>
<tr>
<th>222</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(<span style="color: #0000BB">trim</span><span style="color: #007700">(</span><span style="color: #0000BB">$s</span><span style="color: #007700">)!=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">)</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$s</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>223</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>224</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>225</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;</td>
</tr>
<tr>
<th>226</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">escape</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">){</span></td>
</tr>
<tr>
<th>227</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">mysql_escape_string</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>228</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>229</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>230</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>231</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #FF8000">//&nbsp;模块类，封装了通用CURD模块操作，建议所有模块都继承此类。</span></td>
</tr>
<tr>
<th>232</th>
<td width="100%" nowrap="" style="color: green;"><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">m&nbsp;</span><span style="color: #007700">{&nbsp;</span></td>
</tr>
<tr>
<th>233</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;var&nbsp;<span style="color: #0000BB">$db</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>234</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;var&nbsp;<span style="color: #0000BB">$table</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>235</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;var&nbsp;<span style="color: #0000BB">$fields</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>236</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;var&nbsp;<span style="color: #0000BB">$key</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>237</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">__construct</span><span style="color: #007700">()</span></td>
</tr>
<tr>
<th>238</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>239</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;global&nbsp;<span style="color: #0000BB">$db</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>240</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>241</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">key&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'id'</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>242</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>243</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>244</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;public&nbsp;function&nbsp;<span style="color: #0000BB">__call</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arg</span><span style="color: #007700">)&nbsp;{</span></td>
</tr>
<tr>
<th>245</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">call_user_func_array</span><span style="color: #007700">(array(</span><span style="color: #0000BB">$this</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$name</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">$arg</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>246</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>247</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>248</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;向数据库插入数组格式数据</span></td>
</tr>
<tr>
<th>249</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">add</span><span style="color: #007700">(</span><span style="color: #0000BB">$elem&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>250</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>251</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query_list&nbsp;</span><span style="color: #007700">=&nbsp;array();</span></td>
</tr>
<tr>
<th>252</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if(!<span style="color: #0000BB">$elem</span><span style="color: #007700">)</span><span style="color: #0000BB">$elem&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>253</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;foreach(<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fields&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$f</span><span style="color: #007700">)&nbsp;{</span></td>
</tr>
<tr>
<th>254</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(isset(<span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">])){</span></td>
</tr>
<tr>
<th>255</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">escape</span><span style="color: #007700">(</span><span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">]);</span></td>
</tr>
<tr>
<th>256</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query_list</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"`</span><span style="color: #0000BB">$f</span><span style="color: #DD0000">`&nbsp;"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>257</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query_list1</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"'</span><span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">]</span><span style="color: #DD0000">'"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>258</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>259</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>260</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"insert&nbsp;into&nbsp;`</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">table</span><span style="color: #DD0000">`&nbsp;("</span><span style="color: #007700">.</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,</span><span style="color: #0000BB">$query_list</span><span style="color: #007700">).</span><span style="color: #DD0000">")&nbsp;values&nbsp;("</span><span style="color: #007700">.</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,</span><span style="color: #0000BB">$query_list1</span><span style="color: #007700">).</span><span style="color: #DD0000">")"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>261</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>262</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert_id</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>263</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>264</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>265</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;删除某一条数据</span></td>
</tr>
<tr>
<th>266</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">del</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>267</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>268</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"delete&nbsp;from&nbsp;`</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">table</span><span style="color: #DD0000">`&nbsp;where&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">key</span><span style="color: #007700">.</span><span style="color: #DD0000">"='</span><span style="color: #0000BB">$id</span><span style="color: #DD0000">'"</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>269</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>270</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>271</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;更新数据</span></td>
</tr>
<tr>
<th>272</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">update</span><span style="color: #007700">(</span><span style="color: #0000BB">$id&nbsp;</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$elem&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">FALSE</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>273</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>274</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query_list&nbsp;</span><span style="color: #007700">=&nbsp;array();</span></td>
</tr>
<tr>
<th>275</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if(!<span style="color: #0000BB">$elem</span><span style="color: #007700">)</span><span style="color: #0000BB">$elem&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$_POST</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>276</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;foreach(<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fields&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$f</span><span style="color: #007700">)&nbsp;{</span></td>
</tr>
<tr>
<th>277</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(isset(<span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">])){</span></td>
</tr>
<tr>
<th>278</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">]&nbsp;=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">escape</span><span style="color: #007700">(</span><span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">]);</span></td>
</tr>
<tr>
<th>279</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query_list</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #DD0000">"`</span><span style="color: #0000BB">$f</span><span style="color: #DD0000">`&nbsp;=&nbsp;'</span><span style="color: #0000BB">$elem</span><span style="color: #007700">[</span><span style="color: #0000BB">$f</span><span style="color: #007700">]</span><span style="color: #DD0000">'"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>280</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>281</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>282</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"update&nbsp;`</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">table</span><span style="color: #DD0000">`&nbsp;set&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">','</span><span style="color: #007700">,</span><span style="color: #0000BB">$query_list</span><span style="color: #007700">).</span><span style="color: #DD0000">"&nbsp;where&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">key</span><span style="color: #007700">.</span><span style="color: #DD0000">"&nbsp;='</span><span style="color: #0000BB">$id</span><span style="color: #DD0000">'"&nbsp;</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>283</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>284</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>285</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #FF8000">//&nbsp;统计数量</span></td>
</tr>
<tr>
<th>286</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$where</span><span style="color: #007700">=</span><span style="color: #DD0000">''</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>287</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>288</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"select&nbsp;count(*)&nbsp;as&nbsp;a&nbsp;from&nbsp;`</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">table</span><span style="color: #DD0000">`&nbsp;where&nbsp;1&nbsp;</span><span style="color: #0000BB">$where</span><span style="color: #DD0000">"</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>289</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$res</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">][</span><span style="color: #DD0000">'a'</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>290</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>291</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>292</th>
<td width="100%" nowrap="" style="color: orange;">&nbsp;&nbsp;<span style="color: #FF8000">/*&nbsp;get($id)&nbsp;取得一条数据&nbsp;或&nbsp;</span></td>
</tr>
<tr>
<th>293</th>
<td width="100%" nowrap="" style="color: orange;">&nbsp;&nbsp;*&nbsp;&nbsp;get($postquery&nbsp;=&nbsp;'',$cur&nbsp;=&nbsp;1,$psize&nbsp;=&nbsp;30)&nbsp;取得多条数据</td>
</tr>
<tr>
<th>294</th>
<td width="100%" nowrap="" style="color: orange;">&nbsp;&nbsp;*/</td>
</tr>
<tr>
<th>295</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;<span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">get</span><span style="color: #007700">()</span></td>
</tr>
<tr>
<th>296</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>297</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$args&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">();</span></td>
</tr>
<tr>
<th>298</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if(<span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000BB">$args</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]))&nbsp;return&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__call</span><span style="color: #007700">(</span><span style="color: #DD0000">'get_one'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$args</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>299</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">__call</span><span style="color: #007700">(</span><span style="color: #DD0000">'get_many'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$args</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>300</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>301</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>302</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">get_one</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>303</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>304</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$id&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">is_numeric</span><span style="color: #007700">(</span><span style="color: #0000BB">$id</span><span style="color: #007700">)?</span><span style="color: #0000BB">$id</span><span style="color: #007700">:</span><span style="color: #0000BB">0</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>305</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$res&nbsp;</span><span style="color: #007700">=&nbsp;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;`</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">table</span><span style="color: #DD0000">`&nbsp;where&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">key</span><span style="color: #007700">.</span><span style="color: #DD0000">"='</span><span style="color: #0000BB">$id</span><span style="color: #DD0000">'"</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>306</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;if(isset(<span style="color: #0000BB">$res</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]))return&nbsp;</span><span style="color: #0000BB">$res</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">];</span></td>
</tr>
<tr>
<th>307</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">false</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>308</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>309</th>
<td width="100%" nowrap="" style="color: green;"></td>
</tr>
<tr>
<th>310</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;function&nbsp;<span style="color: #0000BB">get_many</span><span style="color: #007700">(</span><span style="color: #0000BB">$postquery&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">''</span><span style="color: #007700">,</span><span style="color: #0000BB">$cur&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,</span><span style="color: #0000BB">$psize&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">30</span><span style="color: #007700">)</span></td>
</tr>
<tr>
<th>311</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;{</td>
</tr>
<tr>
<th>312</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$cur&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$cur&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">0&nbsp;</span><span style="color: #007700">?</span><span style="color: #0000BB">$cur</span><span style="color: #007700">:</span><span style="color: #0000BB">1</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>313</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$start&nbsp;</span><span style="color: #007700">=&nbsp;(</span><span style="color: #0000BB">$cur&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;*&nbsp;</span><span style="color: #0000BB">$psize</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>314</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"select&nbsp;*&nbsp;from&nbsp;`</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">table</span><span style="color: #DD0000">`&nbsp;where&nbsp;1&nbsp;</span><span style="color: #0000BB">$postquery</span><span style="color: #DD0000">&nbsp;limit&nbsp;</span><span style="color: #0000BB">$start</span><span style="color: #DD0000">&nbsp;,&nbsp;</span><span style="color: #0000BB">$psize</span><span style="color: #DD0000">"</span><span style="color: #007700">;</span></td>
</tr>
<tr>
<th>315</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$query</span><span style="color: #007700">);</span></td>
</tr>
<tr>
<th>316</th>
<td width="100%" nowrap="" style="color: green;">&nbsp;&nbsp;}</td>
</tr>
<tr>
<th>317</th>
<td width="100%" nowrap="" style="color: green;">}</td>
</tr>
<tr>
<th>318</th>
<td width="100%" nowrap="" style="color: green;">

</td>
</tr>
</tbody></table>
</div>       </div>
      <div class="clear"> </div>
    </div>
    <!-- end #content -->
  <div class="clear"> </div>
</div>
  <div id="footer">
    <p>Powered by <a href="http://alpaca.b24.cn/">Alpaca</a></p>
  </div>
<!-- end #footer -->
<script type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3Fd9630d6f04c9cd79d5755f7241fa6dc0' type='text/javascript'%3E%3C/script%3E"));
</script><script src="./代码及注释_files/h.js" type="text/javascript"></script><a href="http://tongji.baidu.com/hm-web/welcome/ico?s=d9630d6f04c9cd79d5755f7241fa6dc0" target="_blank"><img border="0" src="./代码及注释_files/21.gif" width="20" height="20"></a>

</div></body></html>